function show_detail(){
	
	var $el = $(this);
	
	$.getJSON($(this).attr('href'),function(json){
		
		var tr = '';
		
		$.each(json,function(i,item){
			
			tr += '<tr>'+'<td>'+item.station_no+'</td>'+'<td>'
				+item.station_name+'</td>'+'<td>'
				+item.arrive_time+'</td>'+'<td>'
				+item.start_time+'</td>'+'<td>'
				+item.cost_time+'</td>'+'<td>'
				+item.distance+'</td>'+'</td>'
				+(/^[dDgGcC]/.test($el.text())?('<td>'+(item.yd||'--')+'</td>'+'<td>'+(item.ed||'--')+'</td>'+'<td>'+(item.td||'--')+'</td>'):('<td>'
				+(item.yz||'--')+'<td>'+(item.rz||'--')+'</td>'))
				+'<td>'+(item.yw||'--')+'</td>'+'<td>'
				+(item.rw||'--')+'</td>'
				+'</tr>';
			
		});
		
		tr = '<table>'+'<thead><tr><th>站次</th><th>站名</th><th>到时</th><th>开时</th><th>耗时</th><th>里程</th>'
			+(/^[dDgGcC]/.test($el.text())?'<th>一等</th><th>二等</th><th>特等</th>':'<th>硬座</th><th>软座</th>')
			+'<th>硬卧</th><th>软卧</th></tr></thead>'
		+'<tbody>'+tr+'</tbody>'+'</table>';
		tr = '<tr class="sub" id="'+$el.text().replace('/','-')+'"><td colspan="8"><div class="checi"><span class="arr"></span><a href="#" class="close">关闭</a>'+tr+'</div></td></tr>';

		if($('#'+$el.text().replace('/','-')).length==0){
			$el.parent().parent().after(tr)
			$('#'+$el.text().replace('/','-')).find('.close').click(function(){
				$('#'+$el.text().replace('/','-')).remove();
				return false;
			});
				
		}	
		else
			$('#'+$el.text().replace('/','-')).remove();
		
	});
	
	return false;
}



$(function($){
	
	//$('#from,#to').suggest('/api/s.php');
	
	//输入日期	
	$('#departureDate').datepicker({dateFormat:'yy-mm-dd',minDate:'0',maxDate:'+29D',numberOfMonths: 2});
	
	
	//筛选
	$('#changeTrain').change(function(){
		$('#result-data tbody tr').hide();
		$('#result-data tbody tr[class^="'+$(this).val()+'"]').show();
		if($(this).val()=='ALL')$('#result-data tbody tr').show();
	});
	
	
	//日期导航
	function getDate(n,d){
		var day = ['周日','周一','周二','周三','周四','周五','周六'];
		var s = $('#departureDate').val();
		s = s.split('-');
		var newDate = new Date(s[0],s[1]-1,s[2]);
		var now = new Date();
		date = new Date(newDate.getFullYear(),newDate.getMonth(),newDate.getDate()+n);
		var zero = date.getMonth()+1<10 ? '0' : '';
		w = d ? day[date.getDay()] : '';
		var z = Number(date.getDate())<10?'0':'';
		return date.getFullYear()+'-'+zero+(date.getMonth()+1)+'-'+z+date.getDate()+w;
	}
	
	var tab=$('#result-tab-navi li:first');
	for(i=0;i<=6;i++){
		var url = '?from='+$('#from').val()
			+'&to='+$('#to').val()
			+'&departureDate='+getDate(i-3);
		url = encodeURI(url);
		$('a',tab).text(getDate(i-3,true).substr(5)).attr('href',url);
		tab=tab.next();
	};
	
	

	
	//输入检查
	$('#query-form').submit(function(){
		var submit = true;
		$('input[required="required"]').each(function(){
			if($(this).val()==''){
				$(this).addClass('ui-state-error');
				$(this).next().show();
				submit = false;
			}
		})
		.focus(function(){ 
			$(this).removeClass('ui-state-error').next().hide(); 
		});

		return submit;
	});
	
});
